package com.edu.cmsservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edu.cmsservice.domain.CrmBanner;
import com.edu.cmsservice.service.CrmBannerService;
import com.edu.commonutils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author ljw
 * @since 2022-09-21
 */
@Api("放映片后台接口")
@RestController
//@CrossOrigin
@RequestMapping("/cmsservice/banneradmin")
public class CrmBannerControllerAdmin {

    @Autowired(required = false)
    private CrmBannerService crmBannerService;


    @GetMapping("/pagebanner/{current}/{limit}")
    @ResponseBody
    public R page(@PathVariable("current") Integer current,
                  @PathVariable("limit") Integer limit){

        Page<CrmBanner> page=new Page<>(current,limit);

        crmBannerService.page(page,null);

        return R.ok().data("rows",page.getRecords()).data("total",page.getTotal());
    }

    @ApiOperation(value = "新增Banner")
    @CacheEvict(value = "banner", allEntries=true)
    @GetMapping("/save")
    @ResponseBody
    public R save(@RequestBody CrmBanner crmBanner ){
        crmBannerService.save(crmBanner);
        return R.ok();
    }

    @ApiOperation(value = "获取Banner")
    @GetMapping("get/{id}")
    public R get(@PathVariable String id) {
        CrmBanner banner = crmBannerService.getById(id);
        return R.ok().data("item", banner);
    }


    @ApiOperation(value = "修改Banner")
    @PutMapping("update")
    @CacheEvict(value = "banner", allEntries=true)
    public R updateById(@RequestBody CrmBanner banner) {
        crmBannerService.updateById(banner);
        return R.ok();
    }

    @ApiOperation(value = "删除Banner")
    @DeleteMapping("remove/{id}")
    @CacheEvict(value = "banner", allEntries=true)
    public R remove(@PathVariable String id) {
        crmBannerService.removeById(id);
        return R.ok();
    }


}

